Return
A Return statement exits a handler and returns a value. When AppleScript executes a Return statement, it stops handler execution and resumes execution at the place in the script where the handler was called, using the value returned as the value of the handler.SYNTAX
return expressionwhereexpression is an AppleScript expression. When AppleScript executes a Return statement, it returns the value of the expression. Expressions are described in Chapter 6, "Expressions."
EXAMPLE
To return a value and exit a subroutine, include a Return statement in the body of the subroutine. For example, the following statement returns the integer2
:
return 2If you include a Return statement without an expression, AppleScript exits the subroutine immediately and no value is returned.NOTES
If a subroutine does not include a Return statement, AppleScript executes the statements in the subroutine and, after handling the last statement, returns
the value of the last statement in the subroutine. If the last statement does not return a value, then no value is returned.When AppleScript has finished executing a subroutine (that is, when it executes a Return statement or the last statement in the subroutine), it
passes control to the place in the script immediately after the place where
the subroutine was called.